package cn.niitcxl.services.impl;

import cn.niitcxl.domain.eduFile;
import cn.niitcxl.mapper.FileMapper;
import cn.niitcxl.services.FilesServices;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

@Service
public class FileServicesImpl extends ServiceImpl<FileMapper, eduFile> implements FilesServices {
    /**
     *
     * @param fileType 文件类型idt
     * @param currentPage 当前页码
     * @param pageSize 页码大小
     * @param fileName 根据文件名称查询
     * @return
     */
    @Override
    public IPage<eduFile> getPageByCondition(String fileType, Long currentPage, Long pageSize, String fileName) {

        //创建查询条件对象
        QueryWrapper<eduFile> queryWrapper = new QueryWrapper<>();
        //设置条件对象
        queryWrapper.eq("file_type",fileType);

        //设置分页大小
        IPage<eduFile> page = new Page<eduFile>(currentPage,pageSize);
        //设置条件
        if (Strings.isNotEmpty(fileName)){
            queryWrapper.like("file_name",fileName);
        }

        //对上传的文件做时间的排序
        queryWrapper.orderByDesc("insert_date");

        IPage<eduFile> iPage = baseMapper.selectPage(page,queryWrapper);
        return iPage;
    }
}